<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

<%@ page import="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter" %>
<%@ page import="org.springframework.security.core.AuthenticationException" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN" lang="zh-CN">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta http-equiv="Content-Language" content="zh-CN"/>
	<title>Jilujia</title>
	<link rel="stylesheet" href="<c:url value="/resources/styles/blueprint/screen.css" />" type="text/css" media="screen, projection" />
	<link rel="stylesheet" href="<c:url value="/resources/styles/blueprint/print.css" />" type="text/css" media="print" />
	<!--[if lt IE 8]>
	        <link rel="stylesheet" href="<c:url value="/resources/blueprint/ie.css" />" type="text/css" media="screen, projection" />
	<![endif]-->
	<link rel="stylesheet" href="<c:url value="/resources/styles/booking.css" />" type="text/css" media="screen" />
    <script type="text/javascript" src="<c:url value="/resources/js/jquery-1.8.2.min.js" /> "></script>
	<script type="text/javascript" src="<c:url value="/resources/js/json.min.js" /> "></script>
</head>
<body>
	<div class="span-9">
		<c:if test="${not empty param.login_error}">
			<div class="error">
				Your login attempt was not successful, try again.<br /><br />
				Reason: <%= ((AuthenticationException) session.getAttribute(UsernamePasswordAuthenticationFilter.SPRING_SECURITY_LAST_EXCEPTION_KEY)).getMessage() %>
			</div>
		</c:if>
		<form id="LoginForm" action="<c:url value="/ajaxLoginProcess" />" method="post">
			<fieldset>
				<legend>Login Information</legend>
				<p>
					<label for="j_username">User:</label>
					<br />
					<input type="text" name="j_username" id="j_username" <c:if test="${not empty param.login_error}">value="<%= session.getAttribute(UsernamePasswordAuthenticationFilter.SPRING_SECURITY_LAST_USERNAME_KEY) %>"</c:if> />
				</p>
				<p>
					<label for="j_password">Password:</label>
					<br />
					<input type="password" name="j_password" id="j_password" />
				</p>
				<p>
					<input type="checkbox" name="_spring_security_remember_me" id="remember_me" />
					<label for="remember_me">Don't ask for my password for two weeks:</label>
				</p>
				<p>
					<a href="javascript:loginSubmit()" id='btn_login' class='rndbutton'><span>Login</span></a>
				</p>
			</fieldset>
		</form>
	</div>
	<script type='text/javascript'>
		<!--
		function loginSubmit(){
			var form = $('#LoginForm').serialize();
			$.post('<c:url value="/ajaxLoginProcess" />',form,function(data){
				if(data.error == 1)
		    		alert(data.messages);
				else if (data.error == 0){
					alert("success");
					//change header
					parent.$("#topbar").html("<p>Welcome,<a href='<c:url value="/users/go"/>'>"+data.nickName+"</a>|<a href='<c:url value="/logout"/>'>Logout</a></p>");
					parent.$.fancybox.close();
					
				}
			});
		}
		//-->
	</script>
</body>
</html>
